package com.example.demo.web;

import com.example.demo.entity.Org;
import com.example.demo.service.IOrgService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("orgs")
public class OrgController {

    @Autowired
    private IOrgService orgService;



    @ApiOperation(value="获取组织", notes="根据组织id获取组织")
    @ApiImplicitParam(name = "id", value = "组织ID", required = true, dataType = "Integer")
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Org org(@PathVariable Integer id){
        return orgService.getOrgById(id);
    }



    @ApiOperation(value = "分页获取组织信息",notes = "根据页码和每页数量获取组织")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "Integer")
    })
    @RequestMapping(value = "/{pageNum}/{pageSize}",method = RequestMethod.GET)
    public List<Org> orgs(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        return orgService.findAllOrgs(pageNum,pageSize);
    }
}
